using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using cframework_xlua;
using Newtonsoft.Json;

namespace cframework_xlua
{
    [EssentialTools("xcrun", "https://developer.apple.com/xcode/")]
    [CreateAssetMenu(menuName = "cframework_xlua/ChannelUtil_AppleStore")]
    public class ChannelUtil_AppleStore : ChannelUtil
    {
        [Essential]
        public string username;
        [Essential]
        public string password;


        public override bool Deploy(BuildPlayerSetting bps, string projectPath, string destPath, string paramStr, ref string downloadUrl)
        {
            downloadUrl = null;
            var cliPath = bps.deviceToolPaths.GetCmdToolPath("xcrun");

            var ret = CommandLineTool.RunCommand2(cliPath, $"altool --upload-app -f {projectPath} --type ios -u {username} -p {password}", System.IO.Path.GetDirectoryName(Application.dataPath));
            if (ret.ExitCode != 0)
            {
                Debug.LogError("output: " + ret.StdOut);
                Debug.LogError("error: " + ret.StdErr);

                return false;
            }

            return true;
        }
    }
}